package com.jacky.me.teamtalk_example;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

import java.util.List;

import am.immodule.DB.entity.UserEntity;
import am.immodule.IM;
import am.immodule.Model.Beans.RecentInfo;
import am.immodule.Model.Beans.TextMessage;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        findViewById(R.id.login).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                IM.getIntance().userLogin("123", "123");
            }
        });

        findViewById(R.id.send).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                List<RecentInfo> recentSessionList = IM.getIntance().imService.getSessionManager().getRecentListInfo();
                //IM.getIntance().imService.getSessionManager().findPeerEntity(recentSessionList.get(1).getSessionKey())
                //PeerEntity
                UserEntity loginUser = IM.getIntance().imService.getLoginManager().getLoginInfo();
                TextMessage textMessage = TextMessage.buildForSend("你好", loginUser,
                        IM.getIntance().imService
                                .getSessionManager()
                                .findPeerEntity(recentSessionList.get(1).getSessionKey()));
                /** 发送 */
                IM.getIntance().imService.getMessageManager().sendText(textMessage);
                /** 结束 */
            }
        });
    }
}
